/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"FC75D36B-982B-465E-8A37-D8CBA2B0E1C5",variableType:4}
 */
var f_version = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"CDA7EAA4-811F-452F-A457-7C56DC560971"}
 */
var f_producto = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"05216709-D220-46B2-9D9D-D6E5A1C3D2E6"}
 */
var f_descripcion = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"4B53D736-F1A7-42CC-BF8F-CE1962D8690A",variableType:4}
 */
var f_hubo_art = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"D695CAFD-1E88-4F77-8623-0F042925FF3D",variableType:4}
 */
var f_inactivo = 0;

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"1ACF389E-29FB-490E-8F14-350E238DE63A"}
 */
function iniciar(firstShow, event) 
{
	if (firstShow)
	{
		foundset.loadAllRecords();
		databaseManager.setAutoSave(true);
		f_producto = null
		f_inactivo = null;  // primera busqueda sin inactivos
		buscar(null);
	}
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"59C0701E-F556-4E1E-8799-A2DFCD30004D"}
 * @AllowToRunInFind
 */
function buscar(event) 
{
foundset.loadAllRecords();  
if(controller.find() == false)
{
	globals.gMensaje='No encontró productos (find)';
	globals.DIALOGS.showInfoDialog('Calculo Costos',  globals.gMensaje,  "OK") //  30/12/2013
	return false; 
}

if (f_producto != null)
	// TODO   ver esto
	
	// cod_producto='%' + f_cod_producto + '%';  //  buscar en cualquier posicion lo ingresdao
	producto_id = f_producto; // busca exactamente el codigo 

/*	
if (f_version != null)
	version_id = f_version;
	*/



if(f_inactivo != 1)  // solo activos 
	inactivo = 0;
else  
	inactivo = 1;// solo inactivos   
	
/*   vale si se toma versiones como data provider del form
if(f_inactivo != null)
{
if(f_inactivo != 1)  // solo versiones inactivas 
	marca_activa = 0;
else  
	marca_activa = 1;// solo versiones activas
}  */

var found = controller.search()
if(found == 0)
{
	globals.gMensaje = 'No encontró versiones del producto en ese rango'
	globals.DIALOGS.showInfoDialog('Calculo Costos',  globals.gMensaje,  "OK")  //  30/12/2013
	
	return true;
} 
/*
if (f_version != null)
	f_version = version_id_default;   */   // no porque solo trea la default

return true;
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"5A5EEFAE-0981-4737-868A-46B13D67F7C7"}
 */
function todos(event) 
{
	f_producto = null;
	f_version = null;
	if(event.getElementName() == 'todos') 
		buscar(null);
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"DEA4249C-8F31-48C4-8F2A-63FCD7828734"}
 */
function onAction_producto(event) 
{  
	buscar(null);
 
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"D4F299E1-F8B8-4D91-95DD-CCDAF910BC9A"}
 */
function precision(event) 
{
	// PIDE PRECISION  //08-10-2013
	var $win = application.createWindow('pide_prec',JSWindow.MODAL_DIALOG)
	$win.show(forms.despiece_tree_precision)
	
	// ARMA FORMATO   //08-10-2013
	scopes.globals.gprecision_formato_costo = scopes.globals.armar_formato_numero(scopes.globals.gprecision_dec_costo)
	scopes.globals.gprecision_formato_cant = scopes.globals.armar_formato_numero(scopes.globals.gprecision_dec_cant)
	scopes.globals.gprecision_formato_cant_comp = scopes.globals.armar_formato_numero(scopes.globals.gprecision_dec_cant_comp)
}
